Cómo agregar la etiqueta p (Párrafo) dentro del texto seleccionado como negrita.
document.queryCommand("insertParagraph") no funciona dentro del código.
function makeBold() { const state = document.queryCommandState("bold"); let message; switch (state) { case true: message = "The bold formatting will be removed from the selected text."; break; case false: message = "The selected text will be displayed in bold."; break; default: message = "The state of the 'bold' command is indeterminable."; break; } document.querySelector("#output").textContent = `Output: ${message}`; document.execCommand('bold'); } <div contenteditable="true">Select a part of this text!</div> <button onclick="makeBold();">Test the state of the 'bold' command</button> <hr> <div id="output"></div>